﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import com.gengine.utils.*;
    import flash.utils.*;
    import mortal.game.resource.info.*;
    import mortal.game.view.common.*;

    public class BossConfig extends Object
    {
        private var _map:Dictionary;
        private var _refresh:Dictionary;
        private var _wareDic:Dictionary;
        private var _dicMapPlan:Dictionary;
        private const connect:String = "_";
        private static var _instance:BossConfig;

        public function BossConfig()
        {
            this._map = new Dictionary();
            this._refresh = new Dictionary();
            this._wareDic = new Dictionary();
            this._dicMapPlan = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" BossConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:BossInfo = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new BossInfo();
                _loc_2.code = _loc_3.code;
                _loc_2.name = StringHelper.getString(_loc_3.name);
                _loc_2.level = _loc_3.level;
                _loc_2.attackMode = _loc_3.attackMode;
                _loc_2.type = _loc_3.type;
                _loc_2.avatarId = _loc_3.avatarId;
                _loc_2.mesh = _loc_3.mesh;
                _loc_2.bone = _loc_3.bone;
                _loc_2.texture = _loc_3.texture;
                _loc_2.speed = _loc_3.speed;
                _loc_2.maxLife = _loc_3.maxLife;
                _loc_2.maxMana = _loc_3.maxMana;
                _loc_2.modelScale = _loc_3.modelScale;
                _loc_2.aiBehaviorLifeAction = _loc_3.aiBehaviorLifeAction;
                _loc_2.selfEffect = _loc_3.selfEffect;
                _loc_2.corpseTime = _loc_3.corpseTime;
                _loc_2.bodySize = _loc_3.bodySize;
                _loc_2.category = _loc_3.category;
                _loc_2.mouseArea = _loc_3.mouseArea;
                _loc_2.hangModel = _loc_3.hangModel;
                _loc_2.topTalk = _loc_3.topTalk;
                _loc_2.birthEffect = _loc_3.birthEffect;
                _loc_2.aiBehavior = _loc_3.aiBehavior;
                _loc_2.physDefense = _loc_3.physDefense;
                _loc_2.deathEffect = _loc_3.deathEffect;
                _loc_2.attack = _loc_3.attack;
                _loc_2.maxLife = _loc_3.maxLife;
                _loc_2.maxMana = _loc_3.maxMana;
                _loc_2.magicDefense = _loc_3.magicDefense;
                _loc_2.penetration = _loc_3.penetration;
                _loc_2.jouk = _loc_3.jouk;
                _loc_2.hit = _loc_3.hit;
                _loc_2.crit = _loc_3.crit;
                _loc_2.toughness = _loc_3.toughness;
                _loc_2.block = _loc_3.block;
                _loc_2.expertise = _loc_3.expertise;
                _loc_2.dialogId = _loc_3.dialogId;
                this._map[_loc_2.code] = _loc_2;
            }
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_boss.json");
            this.write(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_boss_refresh.json");
            this.writeRefresh(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_boss_refresh_defense.json");
            this.writeRefresh(_loc_1);
            return;
        }// end function

        private function writeRefresh(param1:Object) : void
        {
            var _loc_2:TBossRefresh = null;
            var _loc_3:Object = null;
            var _loc_4:String = null;
            var _loc_5:Array = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TBossRefresh();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._refresh[_loc_2.id] = _loc_2;
                if (_loc_2.wave > 0)
                {
                    this._wareDic[_loc_2.wave] = _loc_2;
                }
                _loc_4 = _loc_2.mapId + this.connect + _loc_2.plan;
                if (!this._dicMapPlan[_loc_4])
                {
                    this._dicMapPlan[_loc_4] = [];
                }
                _loc_5 = this._dicMapPlan[_loc_4];
                _loc_5.push(_loc_2);
            }
            return;
        }// end function

        public function getRefreshItem(param1:int) : TBossRefresh
        {
            return this._wareDic[param1];
        }// end function

        public function getRefreshByMapId(param1:int, param2:Boolean = true) : Array
        {
            var _loc_4:TBossRefresh = null;
            var _loc_3:Array = [];
            for each (_loc_4 in this._refresh)
            {
                
                if (_loc_4.mapId == param1)
                {
                    _loc_3.push(_loc_4);
                }
            }
            if (param2)
            {
                _loc_3.sort(this.sortRefresh);
            }
            return _loc_3;
        }// end function

        public function getRefreshByMapIdAndRound(param1:int, param2:int) : TBossRefresh
        {
            var _loc_4:TBossRefresh = null;
            var _loc_3:* = this.getRefreshByMapId(param1);
            var _loc_5:int = 0;
            while (_loc_5 < _loc_3.length)
            {
                
                _loc_4 = _loc_3[_loc_5];
                if (_loc_4.round == param2)
                {
                    return _loc_4;
                }
                _loc_5++;
            }
            return null;
        }// end function

        private function sortRefresh(param1:TBossRefresh, param2:TBossRefresh) : int
        {
            if (param1.plan <= param2.plan)
            {
                return -1;
            }
            return 1;
        }// end function

        public function getRefresById(param1:int) : TBossRefresh
        {
            return this._refresh[param1] as TBossRefresh;
        }// end function

        public function getRefreshByPlan(param1:int) : TBossRefresh
        {
            var _loc_2:TBossRefresh = null;
            for each (_loc_2 in this._refresh)
            {
                
                if (_loc_2.plan == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getRefreshByMapAndPlan(param1:int, param2:int) : Array
        {
            if (this._dicMapPlan[param1 + this.connect + param2])
            {
                return this._dicMapPlan[param1 + this.connect + param2];
            }
            return [];
        }// end function

        public function getInfoByCode(param1:int) : BossInfo
        {
            return this._map[param1];
        }// end function

        public static function get instance() : BossConfig
        {
            if (_instance == null)
            {
                _instance = new BossConfig;
            }
            return _instance;
        }// end function

    }
}
